#ifndef __CONN_QUEUE_H__
#define __CONN_QUEUE_H__

#include <unistd.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

enum conn_states 
{
    conn_start,     
    conn_read,       
    conn_closing
};

typedef struct cq_item 
{
	int sfd;
	int ev_flags;
	enum conn_states init_state;
	struct cq_item* next;
} CQ_ITEM;

class CQ
{
public:
	void init();
	void push( CQ_ITEM* item );
	CQ_ITEM* pop();
	void free( CQ_ITEM* item );
	CQ_ITEM* item_from_freelist();
	int add_to_freelist( CQ_ITEM* item );
private:
	CQ_ITEM* head;
	CQ_ITEM* tail;
	pthread_mutex_t cq_lock;
	int free_item_curr;
	int free_item_total;
	CQ_ITEM** freeitems;
};

#endif